package com.wms.controller;

import com.wms.bean.PageBean;
import com.wms.bean.ResultBean;
import com.wms.core.R;
import com.wms.dto.*;
import com.wms.entity.Allocate;
import com.wms.entity.BReplenishmentDerail;
import com.wms.entity.BReviewDetails;
import com.wms.entity.ReplenishmentOrder;
import com.wms.service.AllocateService;
import com.wms.service.BReplenishmentDerailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/restocking")
@Api(tags = "调度业务中的补货业务--张开心")
@Slf4j
public class BReplenishmentDerailController {
    @Autowired
    BReplenishmentDerailService bReplenishmentDerailService;

    @PostMapping("/query")
    @ApiOperation(value = "条件以及模糊及所有查询补货单明细")
    public ResultBean<List<BReplenishmentDerail>> query(
            @ApiParam(value = "补货单更新信息", required = true) @RequestBody BReplenishmentsDerailDTO dto
    ) {
        log.info("补货单列表");
        System.out.println(dto);
        PageBean<List<BReplenishmentDerail>> pageBean = bReplenishmentDerailService.queryOrderDerail(dto);
        System.out.println(pageBean);
        return R.success("查询成功", pageBean);
    }

    @PostMapping("/queryReplenishment")
    @ApiOperation(value = "补货单查询")
    public ResultBean queryReplenishment(
            @ApiParam(value = "补货单更新信息", required = true) @RequestBody BReplenishmentDerailDTO bReplenishmentDerailDTO
    ) {
        log.info("补货单列表条件内容{}",bReplenishmentDerailDTO);
        PageBean<List<ReplenishmentOrder>> pageBean = bReplenishmentDerailService.queryOrders(bReplenishmentDerailDTO);
        return R.success("查询成功", pageBean) ;
    }

    @PostMapping("/addOrder")
    @ApiOperation(value = "新增补货单")
    public ResultBean<Integer> insert(
            @ApiParam(value = "新增补货单", required = true) @RequestBody ReplenishmentOrder replenishmentOrder) {
        log.info("新增补货单: {}", replenishmentOrder);
        int rows = bReplenishmentDerailService.addOrder(replenishmentOrder);
        return rows==1?R.success("新增成功"):R.fail("新增失败");
    }


    @GetMapping("/queryStore/{id}")
    @ApiOperation(value = "根据补货明细Id查询门店明细")
    public ResultBean queryPermission(
            @ApiParam(value = "查询用户id", required = true)@PathVariable Integer id
    ) {
        List<BReviewDetails> list = bReplenishmentDerailService.selectStores(id);
        return list.size()!=0?R.success("查询成功",list):R.fail("查询失败");
    }

    @PostMapping("/AuditNum")
    @ApiOperation(value = "审核门店信息业务")
    public ResultBean updateAuditNum(
            @ApiParam(value = "审核所有门店的信息", required = true) @RequestBody StroresAuditDerailDTO stroresAuditDerailDTO) {
        log.info("审核所有门店的信息: {}", stroresAuditDerailDTO);
        int rows = bReplenishmentDerailService.updateAuditNum(stroresAuditDerailDTO);
        return rows==1?R.success("审核成功"):R.fail("审核失败");
    }


    @PostMapping("/addAuditProduct")
    @ApiOperation(value = "审核门店添加商品")
    public ResultBean updateAuditNum(
            @ApiParam(value = "审核门店添加商品", required = true) @RequestBody SaveAuditProductDTO saveAuditProductDTO) {
        log.info("审核所有门店的信息: {}", saveAuditProductDTO);
        int rows = bReplenishmentDerailService.insertProductAndStores(saveAuditProductDTO);
        return rows==1?R.success("添加成功"):R.fail("添加失败");
    }
}
